// pages/person/order/order.js
const req = require('../../../utils/req.js');
const {
  api
} = require('../../../utils/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentData: 0,
    orderlist: [],
  },
  //获取当前滑块的index
  bindchange: function(e) {
    const that = this;
    that.setData({
      currentData: e.detail.current
    })
  },
  //点击切换，滑块index赋值
  checkCurrent: function(e) {
    const that = this;
    if (that.data.currentData === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentData: e.target.dataset.current
      })
    }
  },
  godetail(e) {
    console.log(e)
    let id = e.currentTarget.dataset.item.order_id;
    wx.navigateTo({
      url: `../../person/orderdetail/orderdetail?id=${id}`,
    })
  },
  order_cancel(e) {
    console.log(e)
    let id = e.currentTarget.dataset.cancel_id;
    let {
      order_cancel
    } = api;
    order_cancel.data.orderId = id;
    req.ask(order_cancel).then(res => {
      console.log(res)
    })
    this.init();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.init();
  },

  init() {
    let order_list = api.order_list;
    req.ask(order_list).then(res => {
      console.log(res)
      this.setData({
        orderlist: res.data.data.data
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.init();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})
// let orderlist = [{
//     id: 399,
//     order_id: 302,
//     goods_id: 1181000,
//     goods_name: "母亲节礼物-舒适安睡组合",
//     goods_sn: "Y100300",
//     goods_pic_url: "http://yanxuan.nosdn.127.net/1f67b1970ee20fd572b7202da0ff705d.png",

//   },
//   {
//     id: 400,
//     order_id: 302,
//     goods_id: 1147048,
//     goods_name: "简约知性系列居家地毯 蓝灰格",
//     goods_sn: "1147048",
//     goods_pic_url: "http://yanxuan.nosdn.127.net/1f67b1970ee20fd572b7202da0ff705d.png",

//   },
//   {
//     id: 401,
//     order_id: 302,
//     goods_id: 1181000,
//     goods_name: "母亲节礼物-舒适安睡组合",
//     goods_sn: "Y200400",
//     goods_pic_url: "http://yanxuan.nosdn.127.net/1f67b1970ee20fd572b7202da0ff705d.png",

//   },
// ]